import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.farsoon.childcommon.pojo.BusinessBaseEntity;
import org.junit.jupiter.api.Test;

import java.util.Collections;

public class DemoGenerator
{
    @Test
    void contextLaod()
    {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/mes_data?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8",
                        "root", "a123456789")
                .globalConfig(builder -> {
                    builder
                            .author("Ag1usee")
                            .commentDate("2024-04-07")

//                           .outputDir("src/main/java");
                            //不自动打开输出目录
//                           .disableOpenDir()

                            .dateType(DateType.ONLY_DATE)
                            .commentDate("yyyy/MM/dd")
                            //覆盖已生成文件
                            //.fileOverride()
                            //开启swagger模式
                            .enableSwagger()
                            //指定输出目录 直接右键复制项目根目录的绝对路径
                            .outputDir("E:\\IdeaProjects\\ParentOrChild\\ParentOrChild\\child\\src\\main\\java");

                })
                .packageConfig(builder -> {
                    //设置父包名
                    builder.parent("com.farsoon")
                            //模块名
                            .moduleName("child")
                            .entity("entity")
                            .mapper("dao")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .xml("mappper.xml")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,"E:\\IdeaProjects\\ParentOrChild\\ParentOrChild\\child\\src\\main\\java"));
                })
                .strategyConfig(builder ->
                {
                    //设置需要生成的表名
                    builder.addInclude("t_user")
                            //设置过滤表前缀
                            .addTablePrefix("t_")
                            .entityBuilder()
                            .idType(IdType.ASSIGN_ID)
                            .enableLombok()
                            .enableTableFieldAnnotation()
//                            .superClass(BaseEntity.class);
                            .superClass(BusinessBaseEntity.class)
                            .addSuperEntityColumns("id","create_by","create_name","create_time","update_by","update_name","update_time","is_deleted")
                            .logicDeleteColumnName("is_deleted");
//                          builder
//                            .mapperBuilder()
//                            .enableMapperAnnotation()
//                            .build();
                })
                // 使用Freemarker引擎模板(需要导包)，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                        .execute();
        System.out.println("This is a test");
    }
}
